Home:ALL Converter>R: How to pass rVector through java in connection eval () function

R: How to pass rVector through java in connection eval () function

Ask Time:2018-01-24T14:54:56         Author:Aman Srivastava

Json Formatter

R Code

abc <- function(theta,y) {
    a <- y[1]
    b <- y[2]
    c <- y[3]
    p <- c/(1+(a*(theta-b)))
    return(p) 
}

Java Code

RConnection connection = new RConnection();
connection.eval("source('D:\\\\file.R')");
double theta = 7
double a = 5
double b = 9
double c = 2
double y = "c(a,b,c)" // 'y' is R vector of length 3 (one-dimensional array) 
with a, b, and c parameters as elements
double sum = connection.eval("abc("+theta+","+y+")")
log.info("The sum is=" + sum);

Problem

I want to pass vector (y) on eval function but not able to do that. Is there any way to do that ??

Author:Aman Srivastava,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/48416485/r-how-to-pass-rvector-through-java-in-connection-eval-function
yy